@extends('backend::layout')

@section('title', '新增课程表')

@section('content')
    <form method="post">
        {{ csrf_field() }}
        <div class="box box-primary">
            <div class="box-header with-border">
                @if(!empty($possible))
                <h4 class="text-black f-20">本学期已存在的课程和任课教师 (点击可选择)</h4>
                @endif
                <div class="table-responsive">
                    @foreach($possible as $lesson=>$item)
                        <div style="
                    margin: 20px 0 10px;
                    font-size: 16px;
                    font-weight: bold;
                    color: #ff5b19;
                ">{{ $lesson }}</div>
                        <table class="table">
                            <tbody>
                            <tr>
                                @foreach($item as $val)
                                    <td data-l_code="{{$val->l_code}}" data-tc_code="{{$val->tc_code}}">
                                        <p>{{ $val->teacher->name }} <i class="fa fa-address-book-o"></i></p>
                                    </td>
                                @endforeach
                            </tr>
                            </tbody>
                        </table>
                    @endforeach
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body" style="padding: 50px 20px">
                <h4 class="text-black f-20">
                    @if(!empty($h)) 修改 @else 添加 @endif
                    <span style="color: #008D4C">{{substr($query['year'],0,4)}}年第{{substr($query['year'],5,1)==1?'一':'二'}}学期</span>,
                    <span style="color: #008D4C">
                        {{substr($query['class'],1,1)<4?'初':'高'}}{{substr($query['class'],1,1)}}
                        -{{substr($query['class'],3,1)}}班
                    </span>,
                    <span style="color: #008D4C">{{$weeks[$query['week']]}}</span>,
                    <span style="color: #008D4C">{{
                        $query['sort']==0?'早习':
                            ($query['sort']==9?'晚修1':
                                ($query['sort']==10?'晚修2':
                                    ($query['sort']==11?'晚修4':'第'.$query['sort'].'节')
                                )
                            )
                    }}</span>
                    的课程表
                </h4>
                <div class="row">
                    <div class="col-md-2 col-sm-2 col-xs-2">
                        <select
                                id="l_code"
                                class="selectpicker"
                                name="l_code"
                                data-live-search="true"
                                title="--请选择课程--"
                                data-style="btn-success"
                        >
                            @foreach($lessons as $lesson)
                                <option value="{{$lesson->l_code}}">{{$lesson->name}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-2 col-sm-2 col-xs-2">
                        <select
                                id="tc_code"
                                class="selectpicker"
                                name="tc_code"
                                data-live-search="true"
                                title="--请选择任课教师--"
                                data-style="btn-success"
                        >
                            @foreach($teachers as $teacher)
                                <option value="{{$teacher->tc_code}}">{{$teacher->name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>

            <!-- /.box-body -->
            <div class="box-footer m-b-2">
                <div class="col-lg-4">
                    <button class="btn btn-primary btn-sm" type="submit">
                        <i class="fa fa-check"></i> {{ __('Save') }}
                    </button>
                    &nbsp;&nbsp;&nbsp;
                    <a class="btn btn-default btn-sm" href="javascript:history.back(-1);">
                        <i class="fa fa-undo"></i> {{ __('Back') }}
                    </a>
                    &nbsp;&nbsp;&nbsp;
                    @if(!empty($h))
                        <a href="{{ route('admin.classLessonTeacher.delete', ['id' => $h->id]) }}" class="btn btn-default btn-sm text-danger confirm-delete">
                            <i class="fa fa-trash-o"></i> {{ __('Delete') }}
                        </a>
                    @endif
                </div>
            </div>
            <!-- /.box-footer -->
        </div>
    </form>
    <style>
        p {margin: 0}
        td {border: 1px solid #eeeeee;max-width: 100px}
        td:hover {background: #f4f4f4;cursor: pointer}
    </style>
    <script>
        $("td").click(function(){
            let l_code = $(this).attr('data-l_code')
            let tc_code = $(this).attr('data-tc_code')
            $("#l_code").selectpicker('val',l_code)
            $("#tc_code").selectpicker('val',tc_code)
        });
        @if(!empty($h))
            $("#l_code").selectpicker('val','{{$h->l_code}}')
            $("#tc_code").selectpicker('val','{{$h->tc_code}}')
        @endif
    </script>
@stop